// ConfigFile.h : Declaration of the CConfigFile

#pragma once
#include "resource.h"       // main symbols

#include "ArtFramework.h"
#include "_IConfigFileEvents_CP.h"


#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif



// CConfigFile

class ATL_NO_VTABLE CConfigFile :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CConfigFile, &CLSID_ConfigFile>,
	public ISupportErrorInfo,
	public IConnectionPointContainerImpl<CConfigFile>,
	public CProxy_IConfigFileEvents<CConfigFile>,
	public IDispatchImpl<IConfigFile, &IID_IConfigFile, &LIBID_ArtFrameLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{

public:
	CConfigFile()
	{
	}

	void SetXMLDocument(IXMLDOMDocument2 *pXml)
	{
		m_pXml = pXml;
		m_pXml->get_documentElement(&m_pElement);
	}

	IXMLDOMDocument2* GetXMLDocument()
	{
		return m_pXml.p;
	}

private:
	CComQIPtr<IXMLDOMDocument2>	m_pXml;
	CComQIPtr<IXMLDOMElement>	m_pElement;
	CComBSTR					m_strFullName;
	HRESULT CreateXmlFile(BSTR strFullName);
	//HRESULT LoadXmlFile(BSTR strFullName);
	HRESULT CreateNode(BSTR strNodePath, IXMLDOMNode **pNodeOut);

public: // com
DECLARE_REGISTRY_RESOURCEID(IDR_CONFIGFILE)


BEGIN_COM_MAP(CConfigFile)
	COM_INTERFACE_ENTRY(IConfigFile)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
	COM_INTERFACE_ENTRY(IConnectionPointContainer)
END_COM_MAP()

BEGIN_CONNECTION_POINT_MAP(CConfigFile)
	CONNECTION_POINT_ENTRY(__uuidof(_IConfigFileEvents))
END_CONNECTION_POINT_MAP()
// ISupportsErrorInfo
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);


	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
		m_pElement.p = NULL;
		m_pXml.p = NULL;
	}

public:

	STDMETHOD(ReadText)(BSTR strPath, BSTR* strTextOut, BSTR strDefaultIn);
	STDMETHOD(WriteText)(BSTR strPath, BSTR newValIn);
	STDMETHOD(ReadWin32Rect)(BSTR strPath, LONG_PTR* pValueOut, const LONG_PTR* pDefaultIn);
	STDMETHOD(WriteWin32Rect)(BSTR strPath, LONG_PTR* pNewValueIns);
	STDMETHOD(ReadTypedValue)(BSTR strPath, VARIANT* pvarValueOut, const VARIANT* pvalDefaultIn);
	STDMETHOD(WriteTypedValue)(BSTR strPath, VARIANT newVal);
	STDMETHOD(WriteVariantBool)(BSTR strPath, VARIANT_BOOL bBoolValue);
	STDMETHOD(ReadVariantBool)(BSTR strPath, VARIANT_BOOL *bBoolValue, VARIANT_BOOL *bDefaultValue);

	//STDMETHOD(get_Text)(BSTR strPath, BSTR* pVal);
	//STDMETHOD(put_Text)(BSTR strPath, BSTR newVal);
	//STDMETHOD(get_Win32Rect)(BSTR strPath, BYTE* pRect);
	//STDMETHOD(put_Win32Rect)(BSTR strPath, BYTE* newVal);
	//STDMETHOD(get_TypedValue)(BSTR strPath, VARIANT* pVal);
	//STDMETHOD(put_TypedValue)(BSTR strPath, VARIANT newVal);
	//STDMETHOD(get_aaaaa)(BSTR bbbbb, BSTR* pVal);
	//STDMETHOD(put_aaaaa)(BSTR bbbbb, BSTR newVal);
	STDMETHOD(Load)(BSTR strFullName, VARIANT_BOOL bNotExistCreate);
	STDMETHOD(get_FullName)(BSTR* strFullName);
	STDMETHOD(get_Path)(BSTR* strPath);
	STDMETHOD(Close)(void);
	STDMETHOD(Save)(void);
	STDMETHOD(SaveAs)(BSTR strFullName);
	STDMETHOD(get_XMLDOMDocument)(IDispatch** ppXMLDOMDocument);
};

OBJECT_ENTRY_AUTO(__uuidof(ConfigFile), CConfigFile)
